﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace SOEN341_SCHEDULER_PHASE1
{
    //this will unit test Course
    public static class unitTest_Course
    {
        public static void RunTest()
        {
            Directory.CreateDirectory(GlobalVariablesClass.directory_Current + "\\unitTest");
            StreamWriter sw=null;
            try
            {
                string return_string;
                int return_int;
                double return_double;
                Student return_student;
                bool return_bool;

                sw = new StreamWriter(GlobalVariablesClass.directory_Current + "\\unitTest\\unitTest_Course_OUTPUT.txt",true);
                sw.WriteLine("---------------------------------------------------\n" +
                    "UNIT TEST: Course.cs @ SOEN341_SCHEDULER_PHASE1.sln\n" +
                    DateTime.Now.ToShortDateString() + " @ " + 
                    DateTime.Now.ToShortTimeString() + "\n" +
                    "---------------------------------------------------\n");
                
                //Parameterized Constructor test
                Course tutorial = new Course("Tutorial","TUT123","TT",null,null,null,null,30,4);
                Course lab = new Course("LAB","LAB123","LL",null,null,null,null,15,2);
                Course cs1 = new Course("Test","Test123","DD",null,null,null,null, 45, 34);

                sw.WriteLine("PARAMETERIZED CONSTRUCTOR TEST:\n");
                sw.WriteLine("COURSE PARAMETERS:\n"+
                    "NAME: Test\n" +
                    "COURSE NAME: Test123\n"+
                    "SECTION: DD\n"+
                    "TIMETABLEBLOCK: NULL\n"+
                    "PREREQUISTES: NULL\n"+
                    "TUTORIAL: NULL\n"+
                    "LAB: NULL\n"+
                    "CAPACITY: 45\n"+
                    "CREDITS: 34\n");

                /*
                sw.WriteLine("TUTORIAL PARAMETERS:\n"+
                    "NAME: Tutorial\n" +
                    "COURSE NAME: TUT123\n" +
                    "SECTION: TT\n" +
                    "TIMETABLEBLOCK: NULL\n" +
                    "PREREQUISTES: NULL\n" +
                    "TUTORIAL: NULL\n" +
                    "LAB: NULL\n" +
                    "CAPACITY: 30\n" +
                    "CREDITS: 4\n");

                sw.WriteLine("LAB PARAMETERS:\n" +
                    "NAME: LAB\n" +
                    "COURSE NAME: LAB123\n" +
                    "SECTION: LL\n" +
                    "TIMETABLEBLOCK: NULL\n" +
                    "PREREQUISTES: NULL\n" +
                    "TUTORIAL: NULL\n" +
                    "LAB: NULL\n" +
                    "CAPACITY: 15\n" +
                    "CREDITS: 2\n");
                */

                sw.WriteLine("METHODS TEST:\n\n");
                return_string = cs1.CourseNameProperty;
                sw.WriteLine("public string CourseNameProperty\n" +
                    "RETURN: " + return_string + "\n" +
                    "Validation: Test123 ?= " + return_string + "\t -- " + return_string.Equals("Test123") +"\n");

                
                return_int = cs1.GetNumberOfCredits();
                sw.WriteLine("public int GetNumberOfCredits()\n" +
                      "RETURN: " + return_int + "\n" +
                      "Validation: 34 ?= " + return_int + "\t -- " + (return_int == 34).ToString() + "\n");


                return_int = cs1.GetCapacity();
                sw.WriteLine("public int GetCapacity()\n" + 
                    "RETURN: " + return_int + "\n" +
                    "Validation: 45 ?= " + return_int + "\t -- " + (return_int == 45).ToString() + "\n");

                return_string = cs1.GetName();
                sw.WriteLine("public string GetName()\n" +
                    "RETURN: " + return_string + "\n" +
                    "Validation: Test ?= " + return_string + "\t -- " + return_string.Equals("Test") + "\n");

                return_string = cs1.GetCourseName();
                sw.WriteLine("public string GetCourseName()\n" +
                    "RETURN: " + return_string + "\n" +
                    "Validation: Test123 ?= " + return_string + "\t -- " + return_string.Equals("Test123") + "\n");

                return_string = cs1.GetSection();
                sw.WriteLine("public string GetSection()\n" +
                    "RETURN: " + return_string + "\n" +
                    "Validation: DD ?= " + return_string + "\t -- " + return_string.Equals("DD") + "\n");

                Course toCheck = new Course("ASD","DDER","DD",null,null,null,null,435,1);

                return_bool = cs1.IsSameClassName(toCheck);
                sw.WriteLine("\npublic bool IsSameClassName(Course toCheck)\n" +
                    "toCheck.ToString(): " + toCheck.ToString() + "\n" +
                    "Unit Course Test.ToString(): " + cs1.ToString() + "\n" +
                    "RETURN: " + return_bool + "\n" +
                    "Validation: FALSE ?= " + return_bool + "\t -- " + return_bool.Equals(false) + "\n");

                toCheck = new Course("Test", "Test123", "EE", null, null, null, null, 43, 2);
                return_bool = cs1.IsSameClassName(toCheck);
                sw.WriteLine("\npublic bool IsSameClassName(Course toCheck)\n" +
                    "toCheck - ClassName: " + toCheck.ToString() + "\n" +
                    "Unit Course Test - ClassName: " + cs1.ToString() + "\n" +
                    "RETURN: " + return_bool + "\n" +
                    "Validation: TRUE ?= " + return_bool + "\t -- " + return_bool.Equals(true) + "\n");

                return_bool = cs1.IsTutorialOrLab();
                sw.WriteLine("public bool IsTutorialOrLab() **Expected FAILURE: Tutorial or Lab was not set up for this class. Fix in next test\n" +
                    "RETURN: " + return_bool + "\n" +
                    "Validation: FALSE ?= " + return_bool + "\t -- " + return_bool.Equals(false) + "\n");


                cs1 = new Course("Test", "Test123", "DD", null, null, tutorial, null, 45, 34);

                sw.WriteLine("Tutorial added.\n");
                return_bool = cs1.IsTutorialOrLab();
                sw.WriteLine("public bool IsTutorialOrLab()\n" +
                    "RETURN: " + return_bool + "\n" +
                    "Validation: FALSE ?= " + return_bool + "\t -- " + return_bool.Equals(false) + "\n");

                return_string = cs1.ToString();
                sw.WriteLine("public override string ToString()\n" +
                    "RETURN: " + return_string + "\n");

                sw.WriteLine("\n-----EOF-----");

                sw.Close();
            }
            catch (Exception)
            {
                //could not generate
                if (sw != null) sw.Close();
                Console.WriteLine("Excpetion handleed when writing output of test.");
            }
        }
    }
}
